﻿using System;
using ePipe;
using System.Runtime.CompilerServices;
using System.Threading;
using eLoop;

namespace Letter.IO.Scheduler;

public abstract class APipelineScheduler : PipeScheduler, IDisposable
{
    public APipelineScheduler(ITaskScheduler scheduler)
    {
        this.scheduler = scheduler;
    }

    private ITaskScheduler scheduler;

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public override void Schedule(Action<object> action, object state)
    {
        this.scheduler.Schedule1(action, state);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Schedule(WaitCallback action, object o)
    {
        this.scheduler.Schedule0(action, o);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Schedule(IRunnable runnable, object o)
    {
        this.scheduler.Schedule(runnable, o);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public unsafe void Schedule(delegate*<object, void> action, object o)
    {
        this.scheduler.Schedule(action, o);
    }

    public void Dispose()
    {
        this.scheduler.Dispose();
    }
}
